﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MQ.Core.Common;
using MQ.Core.Entity.System;
using MQ.Core.IService.System;

namespace MQ.Core.Admin.Areas.System.Controllers
{
    /// <summary>
    /// 部门
    /// </summary>
    [Route("api/system/[controller]")]
    public class DepartmentController : ApiController
    {
        private readonly IDepartmentService departmentService;
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="departmentService"></param>
        public DepartmentController(IDepartmentService departmentService)
        {
            this.departmentService = departmentService;
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("page")]
        public object GetPageList(Pagination pagination,string query)
        {
            var data = departmentService.GetPageList<DepartmentEntity>(pagination, query);
            return Success(pagination,data);
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("list")]
        public object GetList(string query)
        {
            var data = departmentService.GetList<DepartmentEntity>(query);
            return Success(data);
        }
        /// <summary>
        /// 树形结构
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("tree")]
        public object GetTree(string companyId)
        {
            return Success();
        }
        /// <summary>
        /// 保存异步
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("save")]
        public async Task<object> SaveAsync(DepartmentEntity entity)
        {
            if (entity.Id > 0) await departmentService.UpdateAsync(entity);
            else await departmentService.AddAsync(entity);
            return Success();
        }
        /// <summary>
        /// yibu删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("delete")]
        public async Task<object> DeleteAsync(string ids)
        {
            await departmentService.DeleteAsync(ids);
            return Success();
        }
    }
}